﻿using System;

using LastLand.Data.Connection;
using LastLand.Data.Global;

using Up2Link.SegString;
using Up2Link.Server;

namespace LastLand.Core.MsgProcessor
{
    public class CMsgInfoAccount : IMessageProcessor
    {
        public void ProcessMessage(CMessagePack<CMessageSS> _msgPack)
        {
            Int32 index = _msgPack.index;
            if (CData.connections[index].IsLoggedIn())
            {
                CUserAccount account = CData.userAccounts[CData.connections[index].Account];
                Int32 deadCharacterCount = account.DeadCharacterList.Count;
                Int32 isCurrentCharacterAlive = CData.world.IsCharacterDead(account.ActiveCharacterIndex) ? 0 : 1;
                String infoString = "account\t" + isCurrentCharacterAlive.ToString() + "\t" + deadCharacterCount.ToString() + "\t";

                CMessageSS okInfoMsg = new CMessageSS(CConst.SERVER_MESSAGE_COMPLETE_INFO, 0, CMessageSS.ENCODING_UTF32, infoString);
                CMessagePack<CMessageSS> okInfoMsgPack = new CMessagePack<CMessageSS>(okInfoMsg, index);
                CData.server.Send(okInfoMsgPack);
            }
            else
            {
                CMessageSS clientNotLoggedInMsg = new CMessageSS(CConst.SERVER_MESSAGE_CLIENT_NOT_LOGGED_IN, 0, CMessageSS.ENCODING_UTF32, "");
                CMessagePack<CMessageSS> clientNotLoggedInMsgPack = new CMessagePack<CMessageSS>(clientNotLoggedInMsg, _msgPack.index);
                CData.server.Send(clientNotLoggedInMsgPack);
            }
        }
    }
}
